//
//  RecommendGameView.swift
//  DouYuZB
//
//  Created by DSDL on 2016/11/3.
//  Copyright © 2016年 鼎商动力. All rights reserved.
//

import UIKit
fileprivate func < <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
    switch (lhs, rhs) {
    case let (l?, r?):
        return l < r
    case (nil, _?):
        return true
    default:
        return false
    }
}

fileprivate func > <T : Comparable>(lhs: T?, rhs: T?) -> Bool {
    switch (lhs, rhs) {
    case let (l?, r?):
        return l > r
    default:
        return rhs < lhs
    }
}

private let kGameCellID = "kGameCellID"
class RecommendGameView: UIView {
    
    //MARK: - 定义数据的属性
    var groupsArr:[BaseGameModel]?{
        didSet{
            //刷新表格
            collectionView.reloadData()
        }
    }
    
    //MARK: - 控件属性
    @IBOutlet weak var collectionView: UICollectionView!
    //MARK: - 系统回调函数
    override func awakeFromNib() {
        super.awakeFromNib()
        autoresizingMask = UIViewAutoresizing()
        collectionView.register(CollectionViewGameCell.NibObject(), forCellWithReuseIdentifier: kGameCellID)
        collectionView.contentInset = UIEdgeInsetsMake(0, 10, 0, 10)
    }
    
}

extension RecommendGameView: UICollectionViewDataSource{
    func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int {
        return groupsArr?.count ?? 0
    }
    func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell {
        
        let cell = collectionView.dequeueReusableCell(withReuseIdentifier: kGameCellID, for: indexPath) as! CollectionViewGameCell
        cell.basegame = groupsArr![(indexPath as NSIndexPath).row]
        return cell
    }
}
